package views.components;

import utils.MessageUtils;

import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

import config.Parameters;

/**
 * HeaderComponent
 * 
 * @author eduard
 * 
 */
@SuppressWarnings("serial")
public class Header extends CustomComponent {

	// Contenedor pare del component necesari per a poder centrarlos
	private HorizontalLayout root;

	// Agrupa la imatge i un vlayout
	private HorizontalLayout subContenedor;

	// agrupara labels
	private VerticalLayout lytLabels;
	private Label lblAyto, lblTitle;
	private Embedded image;

	/**
	 * 
	 * @param title
	 */
	public Header(String title) {

		iniciarVariables(title);

		// definim els estils

		lblAyto.addStyleName("HEADER_TITLE1");
		lblTitle.addStyleName("HEADER_TITLE2");
		lytLabels.setMargin(true);

	}

	private void iniciarVariables(String title) {

		lblAyto = new Label(MessageUtils.getI18n("firm"));
		lblTitle = new Label(title);

		// Serve the image from the theme

		image = new Embedded(null, new ThemeResource(Parameters.ICO_LOGO_PATH
				+ "tavernes-064.png"));

		lytLabels = new VerticalLayout(lblAyto, lblTitle);
		subContenedor = new HorizontalLayout(image, lytLabels);
		root = new HorizontalLayout(subContenedor);
		
		lytLabels.setComponentAlignment(lblTitle, Alignment.MIDDLE_CENTER);
		root.setComponentAlignment(subContenedor, Alignment.MIDDLE_CENTER);
		root.setSizeFull();
		
		
		setCompositionRoot(root);
	}

}
